﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:RoofusUIControls"
    x:Class="RoofusUIControls.HookUpPinsDialog"
    Height="Auto" Width="Auto" Name="dude">
    <UserControl.Resources>
    	<ResourceDictionary>
    		<local:PinConnectionTemplateSelector x:Key="connectionDataTemplateSelector"/>
    		<DataTemplate x:Key="PinConnectionTemplate">
    			<DockPanel LastChildFill="False" Width="Auto" Height="Auto" >
    				<ComboBox IsEditable="False" DockPanel.Dock="Left"
    					x:Name="SourceName"
    					ItemsSource="{Binding Path=InputSurfaceItems, ElementName=dude}"
    					SelectedItem="{Binding Path=Item}"
                          >
    					<ComboBox.ItemTemplate>
    						<DataTemplate>
    							<Label Content="{Binding Path=UserName}"/>
    						</DataTemplate>
    					</ComboBox.ItemTemplate>
    				</ComboBox>
    				<ComboBox IsEditable="False" DockPanel.Dock="Left"
    					ItemsSource="{Binding Path=SelectedItem.OutputPinNames, ElementName=SourceName}"
    					SelectedItem="{Binding Path=Pin}"
    					x:Name="PinName"
                          >
                        <ComboBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel MinWidth="500"/>
                            </ItemsPanelTemplate>
                        </ComboBox.ItemsPanel>
                    </ComboBox>
    				<Button DockPanel.Dock="Left" Content="Remove" Click="Remove_Click" CommandParameter="{Binding}" Tag="{Binding Path=CommandParameter, ElementName=AddButton}" />
    			</DockPanel>
    		</DataTemplate>
    		<DataTemplate x:Key="MultiplePinConnectionTemplate">
    			<DockPanel LastChildFill="False" Width="Auto" Height="Auto">
    				<DockPanel LastChildFill="False" DockPanel.Dock="Top">
    					<Label Content="{Binding Path=Name}" DockPanel.Dock="Left"/>
    					<Button Content="Add" x:Name="AddButton" DockPanel.Dock="Right" Click="AddNewPin_Click" CommandParameter="{Binding}" />
    				</DockPanel>
    				<ListBox Width="Auto" Height="Auto" ItemsSource="{Binding Path=PinSources}" ItemTemplate="{StaticResource PinConnectionTemplate}"/>
    			</DockPanel>
    		</DataTemplate>
    		<DataTemplate x:Key="SinglePinConnectionTemplate">
    			<DockPanel LastChildFill="False">
    				<Label Content="{Binding Path=Name}" DockPanel.Dock="Top"/>
    				<DockPanel LastChildFill="False" Width="Auto" >
    					<ComboBox IsEditable="False" DockPanel.Dock="Left"
    						x:Name="SourceName"
    						ItemsSource="{Binding Path=InputSurfaceItems, ElementName=dude}"
    						DataContext="{Binding Path=PinSource}"
    						SelectedItem="{Binding Path=Item}">
    						<ComboBox.ItemTemplate>
    							<DataTemplate>
    								<Label Content="{Binding Path=UserName}"/>
    							</DataTemplate>
    						</ComboBox.ItemTemplate>
    					</ComboBox>
    					<ComboBox IsEditable="False" DockPanel.Dock="Left"
    						ItemsSource="{Binding Path=SelectedItem.OutputPinNames, ElementName=SourceName}"
    						DataContext="{Binding Path=PinSource}"
    						SelectedItem="{Binding Path=Pin}"
                            x:Name="PinConnectionBox"
                              >
                            <ComboBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel MinWidth="500"/>
                                </ItemsPanelTemplate>
                            </ComboBox.ItemsPanel>
                        </ComboBox>
    				</DockPanel>
    			</DockPanel>
    		</DataTemplate>
    	</ResourceDictionary>
    </UserControl.Resources>
    <DockPanel LastChildFill="False">
        <Grid DockPanel.Dock="Top" Background="{x:Null}">
            <Button Name="Close" Click="Close_Click">Close</Button>
        </Grid>
        <ListView DockPanel.Dock="Top"
                  ItemsSource="{Binding ElementName=dude, Path=InputPins}"
                  ItemTemplateSelector="{StaticResource connectionDataTemplateSelector}"
                  />
    </DockPanel>
</UserControl>
